from django.db import models

# Create your models here.


from django.db import models


# 时间模型
class TemporalModel(models.Model):
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        abstract = True


# 用户表
class User(TemporalModel):
    mobile = models.CharField(max_length=11, help_text='手机号')
    password = models.CharField(max_length=200, help_text='密码', null=True)
    nickname = models.CharField(max_length=100, help_text='昵称', null=True)
    profile_photo = models.CharField(max_length=100, help_text='头像', null=True)
    last_login = models.DateTimeField(help_text='最后登录时间', auto_now=True)
    is_media = models.BooleanField(default=False, help_text='是否是自媒体', null=True)
    is_verified = models.BooleanField(default=False, help_text='是否实名认证', null=True)
    introduction = models.CharField(max_length=100, help_text='简介', null=True)
    certificate = models.CharField(max_length=100, help_text='认证', null=True)
    article_count = models.IntegerField(default=0, help_text='发帖数', null=True)
    read_count = models.IntegerField(default=0, help_text='累计阅读人数', null=True)
    account = models.CharField(max_length=100, help_text='账号', null=True)
    email = models.CharField(max_length=100, help_text='邮箱', null=True)
    status = models.IntegerField(default=1, help_text='状态，是否可用')

    class Meta:
        db_table = 'user_basic'
        verbose_name_plural = '用户'

    def __str__(self):
        return self.nickname


# 用户关系表
class Relation(TemporalModel):
    relationship = [(0, "DELETE"), (1, "FOLLOW"), (2, "BLACKLIST")]
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户ID')
    target_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='target_user',verbose_name='目标用户ID')
    relation = models.IntegerField(verbose_name='关系', choices=relationship)

    class Meta:
        db_table = 'user_relation'
        verbose_name_plural = '用户关系表'


# 用户搜索记录表
class Search(TemporalModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    keyword = models.CharField(max_length=100, verbose_name='关键词', null=True)
    is_deleted = models.BooleanField(default=False, verbose_name="逻辑删除")

    class Meta:
        db_table = "user_search"
        verbose_name_plural = '用户搜索记录表'
